{% from "macros/forms.html" import form_input %}
{% from "macros/worker.html" import worker_status %}
{% set bot_id = bot.id | default("0", true) %}

<div class="bg-base-100 p-4">
  <h1 class="text-3xl font-bold mb-5 w-3/4 ml-[10%]">{{ submit_text }}</h1>
  <p class="text-base-content/60 text-[0.7rem] mb-5 w-1/2 ml-[10%]">ID: {{ bot.id }}</p>
  {% if bot.status %}
    <div class="mb-5 w-3/4 ml-[10%]">{{ worker_status(bot.status) }}</div>
  {% endif %}
  <form id="bot-form" class="w-3/4 ml-[10%]" {{ form_action }} hx-swap="innerHTML"  hx-target="#form-container" hx-target-error="#form-container">
    {% include "partials/admin_form_error.html" %}
    {{ form_input('Name', 'name', bot.name, width="w-3/4") }}
    {{ form_input('Description', 'description', bot.description, width="w-3/4") }}
    {{ form_input('Index', 'index', bot.index, type="number", width="w-3/4") }}

    <label class="select w-3/4 mb-5">
      <span class="label">Bot Type</span>
      <select id="bot_type"
              name="type"
              required
              class="validator select w-full"
              hx-get="{{ url_for('admin.bot_parameters', bot_id=bot_id) }}"
              hx-trigger="change"
              hx-include="this"
              hx-target="#parameters"
              hx-swap="innerHTML"
              {% if bot.type %}disabled{% endif %}>
        {% if not bot.type %}<option value="" selected disabled>Select a bot type</option>{% endif %}
        {% for option in bot_types -%}
          <option value="{{ option.id }}" {% if option.id == bot.type %}selected{% endif %}>{{ option.name }}</option>
        {% endfor -%}
      </select>
      {% if bot.type %}<input type="hidden" name="type" value="{{ bot.type }}">{% endif %}
    </label>
    <div id="parameters" class="w-3/4">{% include "partials/worker_parameters.html" %}</div>

    <input type="submit" class="btn btn-primary w-3/4" value="{{ submit_text }}" />
  </form>
</div>
